home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / ole2book.zip / CHAP11.ZIP / CHAP11 / COSCHMOO / IDROPTGT.CPP < prev    next >
C/C++ Source or Header  |  1993-06-13  |  5KB  |  263 lines

  1. /*
  2.  * IDROPTGT.CPP
  3.  *
  4.  * Implementation of the DropTarget object.
  5.  *
  6.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  7.  *
  8.  * Kraig Brockschmidt, Software Design Engineer
  9.  * Microsoft Systems Developer Relations
  10.  *
  11.  * Internet  :  kraigb@microsoft.com
  12.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  13.  */
  14.  
  15.  
  16. #include "coschmoo.h"
  17.  
  18.  
  19.  
  20. /*
  21.  * CDropTarget::CDropTarget
  22.  * CDropTarget::~CDropTarget
  23.  *
  24.  * Constructor Parameters:
  25.  *  pDoc            LPCSchmooDoc of the document containing us.
  26.  */
  27.  
  28. CDropTarget::CDropTarget(LPCSchmooDoc pDoc)
  29.     {
  30.     m_cRef=0;
  31.     m_pDoc=pDoc;
  32.  
  33.     m_pIDataObject=NULL;
  34.     return;
  35.     }
  36.  
  37.  
  38. CDropTarget::~CDropTarget(void)
  39.     {
  40.     return;
  41.     }
  42.  
  43.  
  44.  
  45.  
  46. /*
  47.  * CDropTarget::QueryInterface
  48.  * CDropTarget::AddRef
  49.  * CDropTarget::Release
  50.  *
  51.  * Purpose:
  52.  *  IUnknown members for CDropTarget object.
  53.  */
  54.  
  55. STDMETHODIMP CDropTarget::QueryInterface(REFIID riid, LPVOID FAR *ppv)
  56.     {
  57.     *ppv=NULL;
  58.  
  59.     //Any interface on this object is the object pointer.
  60.     if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IDropTarget))
  61.         *ppv=(LPVOID)this;
  62.  
  63.     /*
  64.      * If we actually assign an interface to ppv we need to AddRef it
  65.      * since we're returning a new pointer.
  66.      */
  67.     if (NULL!=*ppv)
  68.         {
  69.         ((LPUNKNOWN)*ppv)->AddRef();
  70.         return NOERROR;
  71.         }
  72.  
  73.     return ResultFromScode(E_NOINTERFACE);
  74.     }
  75.  
  76.  
  77. STDMETHODIMP_(ULONG) CDropTarget::AddRef(void)
  78.     {
  79.     return ++m_cRef;
  80.     }
  81.  
  82. STDMETHODIMP_(ULONG) CDropTarget::Release(void)
  83.     {
  84.     ULONG           cRefT;
  85.  
  86.     cRefT=--m_cRef;
  87.  
  88.     if (0L==m_cRef)
  89.         delete this;
  90.  
  91.     return cRefT;
  92.     }
  93.  
  94.  
  95.  
  96.  
  97.  
  98. /*
  99.  * CDropTarget::DragEnter
  100.  *
  101.  * Purpose:
  102.  *  Indicates that data in a drag operation has been dragged over our
  103.  *  window that's a potential target.  We are to decide if it's something
  104.  *  we're interested in or not.
  105.  *
  106.  * Parameters:
  107.  *  pIDataSource    LPDATAOBJECT providing the source data.
  108.  *  grfKeyState     DWORD flags indicating states of keys and mouse buttons.
  109.  *  pt              POINTL coordinates in the client space of the document.
  110.  *  pdwEffect       LPDWORD into which we'll place the appropriate effect
  111.  *                  flag for this point.
  112.  *
  113.  * Return Value:
  114.  *  SCODE           NOERROR
  115.  */
  116.  
  117. STDMETHODIMP CDropTarget::DragEnter(LPDATAOBJECT pIDataSource
  118.     , DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
  119.     {
  120.     HWND        hWnd;
  121.  
  122.     m_pIDataObject=NULL;
  123.  
  124.     if (!m_pDoc->FQueryPasteFromData(pIDataSource))
  125.         {
  126.         *pdwEffect=DROPEFFECT_NONE;
  127.         return NOERROR;
  128.         }
  129.  
  130.     *pdwEffect=DROPEFFECT_MOVE;
  131.  
  132.     if (grfKeyState & MK_CONTROL)
  133.         *pdwEffect=DROPEFFECT_COPY;
  134.  
  135.     m_pIDataObject=pIDataSource;
  136.     m_pIDataObject->AddRef();
  137.  
  138.     hWnd=m_pDoc->Window();
  139.     BringWindowToTop(hWnd);
  140.     UpdateWindow(hWnd);
  141.     m_pDoc->DropSelectTargetWindow();
  142.  
  143.     return NOERROR;
  144.     }
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151. /*
  152.  * CDropTarget::DragOver
  153.  *
  154.  * Purpose:
  155.  *  Indicates that the mouse was moved inside the window represented
  156.  *  by this drop target.  This happens on every WM_MOUSEMOVE, so this
  157.  *  function should be very efficient.
  158.  *
  159.  * Parameters:
  160.  *  grfKeyState     DWORD providing the current keyboard and mouse states
  161.  *  pt              POINTL where the mouse currently is.
  162.  *  pdwEffect       LPDWORD in which to store the effect flag for this point.
  163.  *
  164.  * Return Value:
  165.  *  SCODE           NOERROR
  166.  */
  167.  
  168. STDMETHODIMP CDropTarget::DragOver(DWORD grfKeyState, POINTL pt
  169.     , LPDWORD pdwEffect)
  170.     {
  171.     if (NULL==m_pIDataObject)
  172.         {
  173.         *pdwEffect=DROPEFFECT_NONE;
  174.         return NOERROR;
  175.         }
  176.  
  177.     *pdwEffect=DROPEFFECT_MOVE;
  178.  
  179.     if (grfKeyState & MK_CONTROL)
  180.         *pdwEffect=DROPEFFECT_COPY;
  181.  
  182.     return NOERROR;
  183.     }
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190. /*
  191.  * CDropTarget::DragLeave
  192.  *
  193.  * Purpose:
  194.  *  Informs the drop target that the operation has left its window.
  195.  *
  196.  * Parameters:
  197.  *  None
  198.  *
  199.  * Return Value:
  200.  *  SCODE           NOERROR
  201.  */
  202.  
  203. STDMETHODIMP CDropTarget::DragLeave(void)
  204.     {
  205.     if (NULL==m_pIDataObject)
  206.         return NOERROR;
  207.  
  208.     m_pDoc->DropSelectTargetWindow();
  209.     m_pIDataObject->Release();
  210.  
  211.     return NOERROR;
  212.     }
  213.  
  214.  
  215.  
  216.  
  217.  
  218. /*
  219.  * CDropTarget::Drop
  220.  *
  221.  * Purpose:
  222.  *  Instructs the drop target to paste the data that was just now dropped
  223.  *  on it.
  224.  *
  225.  * Parameters:
  226.  *  pIDataSource    LPDATAOBJECT from which we'll paste.
  227.  *  grfKeyState     DWORD providing current keyboard/mouse state.
  228.  *  pt              POINTL at which the drop occurred.
  229.  *  pdwEffect       LPDWORD in which to store what you do with the data.
  230.  *
  231.  * Return Value:
  232.  *  SCODE           NOERROR
  233.  */
  234.  
  235. STDMETHODIMP CDropTarget::Drop(LPDATAOBJECT pIDataSource
  236.     , DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
  237.     {
  238.     BOOL        fRet=TRUE;
  239.  
  240.     *pdwEffect=DROPEFFECT_NONE;
  241.  
  242.     if (NULL==m_pIDataObject)
  243.         return ResultFromScode(E_FAIL);
  244.  
  245.     m_pDoc->DropSelectTargetWindow();
  246.     m_pIDataObject->Release();
  247.  
  248.     if (m_pDoc->m_fDragSource)
  249.         return ResultFromScode(E_FAIL);
  250.  
  251.     fRet=m_pDoc->FPasteFromData(pIDataSource);
  252.  
  253.     if (!fRet)
  254.         return ResultFromScode(E_FAIL);
  255.  
  256.     *pdwEffect=DROPEFFECT_MOVE;
  257.  
  258.     if (grfKeyState & MK_CONTROL)
  259.         *pdwEffect=DROPEFFECT_COPY;
  260.  
  261.     return NOERROR;
  262.     }
  263.